<template>
  <div class="login-container">
    <div class="flex justify-center mb-20">
      <img src="../../assets/images/logo.svg" class="logo" />
    </div>
    <a-form class="login-form" layout="horizontal" :wrapperCol="{ span: 24 }">
      <a-form-item>
        <a-input
          placeholder="用户名"
          v-model:value="formData.username"
          size="large"
        />
      </a-form-item>
      <a-form-item>
        <a-input
          placeholder="密码"
          v-model:value="formData.password"
          size="large"
        />
      </a-form-item>
      <div class="login-item">
        <div class="auto-login">
          <a-checkbox v-model:checked="checked"> 自动登录 </a-checkbox>
        </div>
        <div class="forget-password">忘记密码</div>
      </div>
      <div>
        <a-button type="primary" block @click="handleSubmit" size="large">
          登录
        </a-button>
      </div>
    </a-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
// import { saveTokens } from '@/utils/cookie'
import { useRouter } from 'vue-router'
import { post } from '@/utils/request'

export default defineComponent({
  setup() {
    const $router = useRouter()
    const checked = ref(false)
    const formData = reactive({
      username: '',
      password: ''
    })
    console.log(process.env.VUE_APP_API_URL)
    const handleSubmit = async () => {
      const { code, msg, data } = await post('admin/user/login', formData)
      if (code === -1) {
        message.error(msg)
      } else {
        message.success('登录成功')
        $router.push('/dashboard/workplace')
      }
    }

    return {
      checked,
      formData,
      handleSubmit
    }
  }
})
</script>

<style lang="less" scoped>
.login-container {
  padding-top: 200px;
  width: 100%;
  height: 100%;
  background-image: url(../../assets/images/login-bg.svg);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: top center;
  .logo {
    width: 128px;
  }
  .login-form {
    max-width: 550px;
    padding: 24px;
    margin: 0 auto;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 6px 12px rgba(140, 152, 164, 0.075);
  }
  .login-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }
}
</style>
